package com.sunxueqi.project.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sunxueqi.framework.web.controller.BaseController;
import com.sunxueqi.framework.web.vo.ResponseData;
import com.sunxueqi.project.system.service.IDictTypeService;
import com.sunxueqi.project.system.vo.DictType;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;

@Api(tags="数据字典类型")
@RestController
@RequestMapping("/system/dict/type")
public class DictTypeController extends BaseController {

	@Autowired
	private IDictTypeService dictTypeService;
	
	/**
	 * 获取所有的数据字典类型
	 * @param dictType
	 * @return
	 */
	@GetMapping("/list")
	public ResponseData list(DictType dictType) {
		startPage();
		List<DictType> list = dictTypeService.selectDictTypeList(dictType);
		return ResponseData.successTableData(list);
	}
	
	/**
	 * 新增数据字典类型
	 * @param dictType
	 * @return
	 */
	@PostMapping
	public ResponseData add(@RequestBody DictType dictType) {
		return super.getResponseDataRow(dictTypeService.add(dictType));
	}
	
	/**
	 * 删除数据字典类型
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/{ids}")
	public ResponseData delete(@PathVariable String ids) {
		String [] idArray = StrUtil.split(ids, ",");
		return super.getResponseDataRow(dictTypeService.deleteDictTypeByIds(idArray));
	}
	
	/**
	 * 修改数据字典类型
	 * @param dictType
	 * @return
	 */
	@PutMapping
	public ResponseData update(@RequestBody DictType dictType) {
		return super.getResponseDataRow(dictTypeService.updateDictType(dictType));
	}
	
	/**
	 * 修改数据字典状态
	 * @param dictType
	 * @return
	 */
	@PutMapping("/changeStatus")
	public ResponseData changeStatus(@RequestBody DictType dictType) {
		return getResponseDataRow(dictTypeService.changeStatus(dictType));
	}
	
}
